package com.moss.cloud.base.biz.controller;

import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.ChildrenFrom;
import com.moss.cloud.base.api.model.from.PositionFrom;
import com.moss.cloud.base.api.model.param.PositionParam;
import com.moss.cloud.base.biz.service.ISysPositionService;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 职位管理前端控制器
 *
 * @author 瑾年
 * @date 2023年12月18日
 */
@RestController
@RequestMapping(ServiceList.BASE + "/position")
public class SysPositionController {
    private final ISysPositionService sysPositionService;

    public SysPositionController(ISysPositionService sysPositionService) {
        this.sysPositionService = sysPositionService;
    }

    /**
     * 职位分页查询
     *
     * @param positionParam
     * @return
     */
    @PostMapping("/positionPage")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "职位分页查询")
    public Result<?> positionPage(@RequestBody PositionParam positionParam){
        return Result.success(sysPositionService.positionPage(positionParam));
    }

    /**
     * 查询职位孩子节点数据
     *
     * @param childrenFrom
     * @return
     */
    @PostMapping("/childrenList")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "查询职位孩子节点数据")
    public Result<?> childrenList(@RequestBody ChildrenFrom childrenFrom){
        return Result.success(sysPositionService.childrenList(childrenFrom));
    }

    /**
     * 职位树结构
     *
     * @param positionParam
     * @return
     */
    @PostMapping("/positionTree")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "职位树结构")
    public Result<?> positionTree(@RequestBody PositionParam positionParam){
        return Result.success(sysPositionService.positionTree(positionParam));
    }

    /**
     * 职位详情
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/position")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "职位详情")
    public Result<?> position(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysPositionService.position(baseFrom));
    }

    /**
     * 新增职位
     *
     * @param positionFrom
     * @return
     */
    @PostMapping("/savePosition")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增职位")
    public Result<?> savePosition(@RequestBody @Validated PositionFrom positionFrom){
        return Result.success(sysPositionService.savePosition(positionFrom));
    }

    /**
     * 更新职位
     *
     * @param positionFrom
     * @return
     */
    @PostMapping("/updatePosition")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "更新职位")
    public Result<?> updatePosition(@RequestBody @Validated PositionFrom positionFrom){
        return Result.success(sysPositionService.updatePosition(positionFrom));
    }

    /**
     * 删除职位
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/removePosition")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除职位")
    public Result<?> removePosition(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(sysPositionService.removePosition(baseFrom));
    }
}
